/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.network.topo.attachment;

import java.awt.Color;
import java.awt.Font;
import java.beans.PropertyChangeEvent;
import java.util.Vector;

import twaver.TWaverConst;
import twaver.TWaverUtil;
import twaver.chart.Item;
import twaver.chart.PieChart;
import twaver.network.ui.ComponentAttachment;
import twaver.network.ui.ElementUI;

public class PieAttachment extends ComponentAttachment{

	private PieChart pie;
	private Item xItem;
	private Item yItem;
	
	public PieAttachment(String name, ElementUI ui) {
		super(name, ui);

		xItem = new Item("x", element.getX(), Color.RED);
		yItem = new Item("y", element.getY(), Color.BLUE);
		Vector items = new Vector();
        items.addElement(xItem);
        items.addElement(yItem);
        pie = new PieChart(items, null, Color.WHITE);
        pie.setValueTextColor(Color.WHITE);
        pie.setValueTextFont(TWaverUtil.getFont(Font.ITALIC, 10));
        pie.getLegendPane().setVisible(false);
        pie.setShadowColor(Color.GRAY.darker());
        
        pie.setOpaque(false);
        
        this.setClosable(true);
        this.setMinimizable(true);
        this.setShrinkable(true);
        this.setStyle(TWaverConst.ATTACHMENT_STYLE_BUBBLE);
        this.setPosition(TWaverConst.POSITION_LEFT);
        this.setDirection(TWaverConst.ATTACHMENT_DIRECTION_TOP_LEFT);
        this.setBorderVisible(true);
        this.setBorderColor(Color.BLACK);
        this.setBodyVisible(true);
        this.setBodyGradient(true);
        this.setBodyColor(new Color(0, 0, 0, 125));
        this.setBodyGradientColor(new Color(255, 255, 255, 125));
        this.setMinimizedIcon(TWaverUtil.getImageIcon("/demo/network/topo/attachment/pie.png"));
        this.setWidth(100);
        this.setHeight(80);
        this.setXOffset(-2);
        
		this.setComponent(pie);
	}

	public void elementPropertyChange(PropertyChangeEvent evt) {
		super.elementPropertyChange(evt);
		if(evt.getPropertyName().equals(TWaverConst.PROPERTYNAME_LOCATION)){
			xItem.setValue(element.getX());
			yItem.setValue(element.getY());
		}
	}
}